package conult

import (
	"3-19yk/common/nacos"
	"fmt"
	"github.com/google/uuid"
	"github.com/hashicorp/consul/api"
)

func Conult() {
	nac := nacos.Config.Consul
	consul, err := api.NewClient(&api.Config{
		Address: fmt.Sprintf("%s:%d", nac.Host, nac.Port),
	})
	if err != nil {
		return
	}
	s := uuid.New().String()
	err = consul.Agent().ServiceRegister(&api.AgentServiceRegistration{
		ID:      s,
		Name:    nac.Name,
		Port:    nac.Port,
		Address: nac.Host, // Replace with the actual address if necessary
		Tags:    []string{"Grpc"},
		Check: &api.AgentServiceCheck{
			Interval:                       "5s",
			Timeout:                        "5s",
			GRPC:                           fmt.Sprintf("%s:%d", nac.Host, nac.Port),
			DeregisterCriticalServiceAfter: "30s",
		},
	})
	if err != nil {
		return
	}
}
